package cs2340.todolist.view;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import cs2340.todolist.application.ToDoListApplication;
import cs2340.todolist.controller.ItemInformationActivity;
import cs2340.todolist.model.ToDoItem;

public class TodoItemButton extends Button {
	
	ToDoItem toDoItem;
	Context context;
	
	/**
	 * constructor for this class
	 * @param context - the context to be used
	 * @param attrs - attribute set to be used
	 * @param toDoItem - todoItem for this button
	 */
	public TodoItemButton(Context context, AttributeSet attrs, ToDoItem toDoItem) {
		super(context, attrs);
		this.context = context;
		this.toDoItem = toDoItem;
		setOnClickListener(new LocalOnClickListener());
		setText(toDoItem.getTitle());
	}
	
	/**
	 * class for listeners of this button
	 */
	private class LocalOnClickListener implements OnClickListener {
		
		/**
		 * when clicked
		 */
		public void onClick(View v) {
			//view/edit item code
			((ToDoListApplication)getContext().getApplicationContext()).getItemInformationManager().setCurrentItem(toDoItem);
			Intent goToItem = new Intent(getContext(),ItemInformationActivity.class);
			getContext().startActivity(goToItem);
		}
	}

}
